/*
 * This file is part of the Sx Framework Library.
 * 
 * Copyright (C) 2013 University of Colorado Denver
 * <min.choi@ucdenver.edu> <shane.transue@ucdenver.edu>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 * copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */
#ifndef SX_DISCRETE_INTEGRATOR_H
#define SX_DISCRETE_INTEGRATOR_H

#include <sxIntegrator.h>
#include <sxArrayList.h>

namespace Sx {
namespace Physics {

class DiscreteIntegrator : public Integrator {
public:
	DiscreteIntegrator(unsigned int nodeCount);
	virtual ~DiscreteIntegrator();

	virtual bool construct(const Util::ArrayList<Eigen::Vector3d> nodes) = 0;

	virtual bool addNodeExternalForce(unsigned int index, const Eigen::Vector3d& force) = 0;
	virtual bool addNodeVelocity(unsigned int index, const Eigen::Vector3d& velocity) = 0;
	virtual bool addNodePosition(unsigned int index, const Eigen::Vector3d& position) = 0;

	virtual bool setNodeExternalForce(unsigned int index, const Eigen::Vector3d& force) = 0;
	virtual bool setNodeExternalForce(unsigned int index, double x, double y, double z) = 0;
	virtual bool setNodeInternalForce(unsigned int index, const Eigen::Vector3d& force) = 0;
	virtual bool setNodeInternalForce(unsigned int index, double x, double y, double z) = 0;
	virtual bool setNodeVelocity(unsigned int index, const Eigen::Vector3d& velocity) = 0;
	virtual bool setNodeVelocity(unsigned int index, double x, double y, double z) = 0;
	virtual bool setNodePosition(unsigned int index, const Eigen::Vector3d& position) = 0;
	virtual bool setNodePosition(unsigned int index, double x, double y, double z) = 0;
	virtual bool setNodeAcceleration(unsigned int index, const Eigen::Vector3d& acceleration) = 0;
	virtual bool setNodeAcceleration(unsigned int index, double x, double y, double z) = 0;

	virtual Eigen::Vector3d getNodeExternalForce(unsigned int index) = 0;
	virtual Eigen::Vector3d getNodeInternalForce(unsigned int index) = 0;
	virtual Eigen::Vector3d getNodeAcceleration(unsigned int index) = 0;
	virtual Eigen::Vector3d getNodeVelocity(unsigned int index) = 0;
	virtual Eigen::Vector3d getNodePosition(unsigned int index) = 0;
	
	virtual void performTimestep(double dt) = 0;
	virtual void reset() = 0;
	virtual void zeroExternalForces() = 0;

	void setSubsteps(unsigned int substeps);
	unsigned int getSubsteps() const;
	unsigned int getNodeCount() const;

	static const unsigned int DEFAULT_SUBSTEPS;

protected:
	unsigned int nodeCount;
	unsigned int substeps;
};

}

}

#endif
